import { http } from "@/utils/http";
import { formatToken } from "@/utils/auth";
import type { ApiResponse } from "./user";

export interface SmsSendResponse {
  sent: boolean;
  expires_in: number;
  debug_code?: string;
}

export const sendBindPhoneCode = (partialToken: string, phone: string) => {
  return http.request<ApiResponse<SmsSendResponse>>(
    "post",
    "/auth/sms/send",
    {
      data: {
        phone,
        scene: "bind_phone"
      }
    },
    {
      headers: {
        Authorization: formatToken(partialToken)
      }
    }
  );
};

export const sendSmsCode = (
  phone: string,
  scene: "login" | "register"
): Promise<ApiResponse<SmsSendResponse>> => {
  return http.request<ApiResponse<SmsSendResponse>>(
    "post",
    "/auth/sms/send",
    {
      data: {
        phone,
        scene
      }
    }
  );
};
